package logic

import (
	"api/model/mysql"
	"context"
	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *goods.AddGoodsRequest) (*goods.AddGoodsResponse, error) {
	// todo: add your logic here and delete this line

	m := mysql.Goods{
		GoodsName:   in.GoodsName,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsNum:    int(in.GoodsNum),
		GoodsStatus: 1,
	}

	mysql.DB.Create(&m)

	return &goods.AddGoodsResponse{
		Id: int64(m.ID),
	}, nil
}
